//
//  UIFont+Extension.swift
//  LiveTrivia
//
//  Created by Gesen on 2017/12/3.
//  Copyright © 2017年 LiveTrivia. All rights reserved.
//

import UIKit

extension UIFont {
    
    enum CustomFont: String {
        case din_medium = "DIN-Medium"
    }
    
    static func custom(_ font: CustomFont, size: CGFloat) -> UIFont {
        return UIFont(name: font.rawValue, size: size) ?? UIFont.systemFont(ofSize: size)
    }
    
}

extension UIFont {
    
    enum DIN {
        case medium
        
        var name: String {
            return "DIN-Medium"
        }
    }
    
    static func din(size: CGFloat, _ weight: DIN) -> UIFont {
        return UIFont(name: weight.name, size: size) ?? .system(size, .regular)
    }
    
    static func regular(size: CGFloat) -> UIFont {
        let name = "PingFangSC-Regular"
        return UIFont(name: name, size: size) ?? .system(size, .regular)
    }
    static func semibold(size: CGFloat) -> UIFont {
        let name = "PingFangSC-Semibold"
        return UIFont(name: name, size: size) ?? .system(size, .semibold)
    }
    static func light(size: CGFloat) -> UIFont {
        let name = "PingFangSC-Light"
        return UIFont(name: name, size: size) ?? .system(size, .light)
    }
    static func medium(size: CGFloat) -> UIFont {
        let name = "PingFangSC-Medium"
        return UIFont(name: name, size: size) ?? .system(size, .medium)
    }
    private static func system(_ size: CGFloat, _ weight: UIFont.Weight) -> UIFont {
        return .systemFont(ofSize: size, weight: weight)
    }
}
